package com.lhb.common.utils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class MouseUtils implements MouseListener, MouseMotionListener {

    Point beginPoint;
    JFrame frame;


    public static MouseUtils Create(JFrame frame) {
        MouseUtils mouseUtils = new MouseUtils();
        mouseUtils.frame = frame;
        mouseUtils.beginPoint = new Point();
        return mouseUtils;
    }


    @Override
    public void mouseClicked(MouseEvent e) {


    }

    @Override
    public void mousePressed(MouseEvent e) {
        beginPoint =e.getLocationOnScreen();
    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    @Override
    public void mouseDragged(MouseEvent e) {
        Point lastPoint = e.getLocationOnScreen();
        Rectangle bounds = frame.getBounds();
        bounds.x = (int)(lastPoint.x - beginPoint.getX());
        bounds.y = (int)(lastPoint.y - beginPoint.getY());
        frame.setBounds(bounds);
    }

    @Override
    public void mouseMoved(MouseEvent e) {

    }
}
